﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Signup.aspx.cs" Inherits="HTComics.Web.User.Signup" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../Css/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(doOnLoad);
        var LOGIN_LENGTH = 6;
        var PWD_LENGTH = 6;

        function doOnLoad() {
            $('#MainContent_btnSignup').button();
            $('#MainContent_btnReset').button();
        }

        function valid() {
            if ($('#MainContent_txtFirstname').val() == '') {
                alert("Please enter first name");
                $('#MainContent_txtFirstname').focus();
                return false;
            }

            if ($('#MainContent_txtLastname').val() == '') {
                alert("Please enter last name");
                $('#MainContent_txtLastname').focus();
                return false;
            }

            if ($('#MainContent_txtLogin').val() == '') {
                alert("Please enter user name");
                $('#MainContent_txtLogin').focus();
                return false;
            }
            else if (/\s/g.test($('#MainContent_txtLogin').val())) {
                alert("User name cannot have spaces");
                $('#MainContent_txtLogin').focus();
                return false;
            }
            else if ($('#MainContent_txtLogin').val().length < LOGIN_LENGTH) {
                alert("The login should be atleast " + LOGIN_LENGTH);
                $('#MainContent_txtLogin').focus();
                return false;
            }

            if ($('#MainContent_txtPassword').val() == '') {
                alert("Please enter password");
                $('#MainContent_txtPassword').focus();
                return false;
            }
            else if ($('#MainContent_txtPassword').val().length < LOGIN_LENGTH) {
                alert("The password should be atleast " + PWD_LENGTH);
                $('#MainContent_txtPassword').focus();
                return false;
            }

            if ($('#MainContent_txtPassword').val() != $('#MainContent_txtConfirmPassword').val()) {
                alert("Password and Confirm Password fields does not match");
                $('#MainContent_txtPassword').focus();
                return false;
            }

            if (!validate($('#MainContent_txtEmail').val()))
            {
                alert('Invalid Email Address');
                $('#MainContent_txtEmail').focus();
                return false;
            }

            return true;
        }

        function validate(address) {

            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            if (reg.test(address) == false) {
                return false;
            }

            return true;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Heading" runat="server">
Signup
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
            <div class="section" id="mainDiv" runat="server">
                <span class="header">
                    New User Signup Form
                </span>

            <div class="content">
                <table align="center" style="border:1px solid #d9d6c4;" cellpadding="5" cellspacing="5" width="360px">
                    <tr>
                        <td class="labelBold">Firstname*</td>
                        <td><asp:TextBox ID="txtFirstname" runat="server" CssClass="textfield" MaxLength="50" Width="220px"></asp:TextBox> </td>
                    </tr>
                    <tr>
                        <td class="labelBold">Lastname*</td>
                        <td><asp:TextBox ID="txtLastname" runat="server" CssClass="textfield" MaxLength="50" Width="220px"></asp:TextBox> </td>
                    </tr>
                    <tr>
                        <td class="labelBold">Username*</td>
                        <td><asp:TextBox ID="txtLogin" runat="server" CssClass="textfield" MaxLength="50" Width="220px"></asp:TextBox> </td>
                    </tr>
                    <tr>
                        <td class="labelBold">Password*</td>
                        <td><asp:TextBox ID="txtPassword" runat="server" TextMode="Password" CssClass="textfield" MaxLength="50" Width="220px"></asp:TextBox> </td>
                    </tr>
                    <tr>
                        <td class="labelBold">Confirm Password*</td>
                        <td><asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password" CssClass="textfield" MaxLength="50" Width="220px"></asp:TextBox> </td>
                    </tr>
                    <tr>
                        <td class="labelBold">Email*</td>
                        <td><asp:TextBox ID="txtEmail" runat="server" CssClass="textfield" MaxLength="100" Width="220px"></asp:TextBox> </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">&nbsp;</td>
                    </tr>        
                    <tr>
                        <td colspan="2" align="center">
                            <asp:Button ID="btnSignup" runat="server" 
                                Text="Signup" OnClientClick="return valid();" onclick="btnSignup_Click"/>
                            
                            <asp:Button ID="btnReset" runat="server" 
                                Text="Reset" OnClientClick="form1.reset();return false;"/>
                        </td>
                    </tr>        
                    <tr>
                        <td colspan="2"  colspan="2" align="center">
                            <asp:Label ID="lblError" runat="server" ForeColor="Red" Visible="false"></asp:Label>
                        </td>
                    </tr>
                </table>
            </div>
            </div>

            <asp:Label ID="lblSuccess" runat="server" ForeColor="Red" Visible="false">
                Congraluations! new user has been created successfully. An email sent to your account
                which contains your login and password. Please keep that email in safe records.
                <br /><br />
                You'll be redirected to the home page in 10 seconds
            </asp:Label>
</asp:Content>
